$(function() {
    var taskTable = null;
    var opts = {
        targetId: "taskTable",
        templateId: "tabletask",
        settings: {
            searchParam: {

            },
            url: DI.queryAreaTaskList,
            ajaxType: "json",
            sourceInterface: {
                INum: "totalSize",
                IData: "records"
            },
            paginationIndexName: {
                "peerpageRows": "pageSize",
                "currentPage": "pageNo"
            }
        },
        customFuncs: {
            selAllcheckbox: function() {
                var curCheckboxs = $("table tbody td input[type=checkbox]");
                for (var i = 0; i < curCheckboxs.length; i++) {
                    if ($(curCheckboxs[i]).attr("disabled") != "disabled") {
                        if ($("#checkTop")[0].checked) {
                            curCheckboxs[i].checked = true;
                        } else {
                            curCheckboxs[i].checked = false;
                        }
                    }
                }
            }
        }
    };
    //实例化数据表，获取主推任务列表信息
    taskTable = SwiftUI.swiftTable.getInstance(opts);

    var mainCtrl = avalon.define({
        $id: "mainController",
        id: "",
        taskTopic: "",
        month: "",
        createTime: "",
        distStatus: "",

        searchTask: function() {
        	var m = $('#month').val();
            var searchParam = {
                "taskTopic": mainCtrl.taskTopic,
                "month": m
            }
            taskTable.search(searchParam);
        },

        exportTask: function() {
            var taskNos="";
            var curCheckboxs = $("table tbody td input[type=checkbox]");
            for (var i = 0; i < curCheckboxs.length; i++) {
                if (curCheckboxs[i].checked) {
                    taskNos=taskNos+$(curCheckboxs[i]).val()+",";
                }
            }
            if (taskNos.length == 0) {
                PLATFORM.showTips("warning", "请先选择任务再进行导出");
                return;
            }
            window.location.href = DI.exportAreaTaskCompleteInfo + "?areaTaskIds=" + taskNos;
        }
    });
    
    PLATFORM.monthpicker("#month",true);
    avalon.scan();
});

/*
 * 分配状态  过滤器
 * 0未分配,1已分配;2修改待分配
 */
avalon.filters.filterAssignStatus = function(str, args, args2) {
    var ret = "未分配";
    if (str == 0) {
        ret = "未分配"
    } else if (str == 1) {
        ret = "已分配";
    } else if (str == 2) {
        ret = "重新分配";
    } else if (str == 3) {
        ret = "分配中";
    }
    return ret;
};

/*
 * 分配状态  过滤器
 * 0未分配,1已分配;2修改待分配
 */
avalon.filters.filterTaskStatus = function(str, args, args2) {
	var ret = "已结束";
    if (str == -1) {
        ret = "已结束"
    } else if (str == 0) {
        ret = "进行中";
    } else if (str == 1) {
        ret = "未开始";
    }
    return ret;
};